
model{
for(i in 1:N){
for (k in 1:K){
s1[i,k]<- se[k]^x[i,k]*((1-se[k])^(1-x[i,k]))
s2[i,k]<- sp[k]^(1-x[i,k])*((1-sp[k])^x[i,k])
}
for (j in 1:K){
for (h in 1:K){
cop[i,j,h]<- c1[j,h]*(-1)^(x[i,j] + x[i,h])/(s1[i,j]*s1[i,h])
con[i,j,h]<- c2[j,h]*(-1)^(x[i,j] + x[i,h])/(s2[i,j]*s2[i,h])
}
}
eta[i] = (prod(s1[i,1:K]) *(1+ sum(cop[i,,])))
theta[i] =(prod(s2[i, 1:K]) *(1+sum(con[i,,])))
prob[i]=pi*eta[i] + (1-pi)*theta[i]
z[i] ~ dpois( - log(prob[i]))
}
t[1:N] ~ dmulti(prob[1:N], n)
for (k in 1:K){
se[k] ~ dbeta( omega1*(kappa1 -2)+1, (1-omega1)*(kappa1-2) +1)
sp[k] ~ dbeta( omega2*(kappa2 -2)+1, (1-omega2)*(kappa2-2) +1)
}
for (l in 1:(K-1)){
for (h in (l+1):K){
c1[l,h] ~ dunif((se[l]-1)*(1-se[h]), (min(se[l],se[h])-se[l]*se[h]))
c2[l,h] ~ dunif((sp[l]-1)*(1-sp[h]), (min(sp[l],sp[h])-sp[l]*sp[h]))
}}
for (h in 1:K){
for (l in h:K){
c1[l,h] <-0
c2[l,h] <-0
}}
omega1 ~ dbeta(1,1)T(0.5,)
omega2 ~ dbeta(1,1)T(0.5,)
kappa1 = kappaMinusTwo1 +2
kappaMinusTwo1~ dgamma(0.01,0.01)
kappa2 = kappaMinusTwo2+2
kappaMinusTwo2 ~ dgamma(0.01,0.01)
pi ~ dbeta(1.8,2)
}
